//
//  PermissionType.swift
//  permission
//
//  Created by Mr.wang on 2018/12/10.
//  Copyright © 2018 Mr.wang. All rights reserved.
//
import Foundation

enum PermissionType {
    case microphone
    case photoLibrary
    case camera
}

extension PermissionType {
    
    var infoDescription: String {
        switch self {
        case .microphone:
            return "NSMicrophoneUsageDescription"
        case .photoLibrary:
            return "NSPhotoLibraryUsageDescription"
        case .camera:
            return "NSCameraUsageDescription"
        }
    }
    
    var displayText: String {
        switch self {
        case .microphone:
            return "麦克风".localized
        case .photoLibrary:
            return "相册".localized
        case .camera:
            return "相机".localized
        }
    }
    
    func checkInfoPlist() {
        guard let _ = Bundle.main.object(forInfoDictionaryKey: infoDescription) else {
            fatalError("请在info.plist中添加\(infoDescription)")
        }
    }
    
    var permission: Permission.Type {
        switch self {
        case .camera:
            return Camera.self
        case .photoLibrary:
            return PhotoLibrary.self
        case .microphone:
            return Microphone.self
        }
       
    }
}
